#!/usr/bin/python
import sys

# open file.
id1 = sys.argv[1]
id2 = sys.argv[2]
fin = open(sys.argv[3],"rb")
fout1 = open(sys.argv[4], "wb")
fout2 = open(sys.argv[5], "wb")

# skip headers.
for line in fin:
	# skip headers.
	if line[0] == "@": continue
	break
	
# print first.
if line.find(id1) != -1:
	fout1.write(line)
else:
	fout2.write(line)
	
# start counting.
i = 0
for line in fin:
	if line.find(id1) != -1:
		fout1.write(line)
	else:
		fout2.write(line)

	if i % 1000000 == 0:
		print i
	i += 1

fin.close()
fout1.close()
fout2.close()
